﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace HomeDms.Imaging
{
    public partial class RotateToolPanel : ImageToolPanel
    {
        public RotateToolPanel()
        {
            InitializeComponent();
        }

        private void trackBar1_Scroll(object sender, EventArgs e)
        {
            trackBar2.Value = trackBar1.Value / 90;
            numericUpDown1.Value = trackBar1.Value;
            Changed();
        }

        protected override void Execute()
        {
            Rotate();
        }

        private void Rotate()
        {
            AForge.Imaging.Filters.RotateNearestNeighbor rotator = new AForge.Imaging.Filters.RotateNearestNeighbor((double)numericUpDown1.Value);
            rotator.FillColor = Color.White;
            Bitmap = rotator.Apply(Bitmap);
            InvalidateImage();
        }

        private void trackBar2_Scroll(object sender, EventArgs e)
        {
            trackBar1.Value = trackBar2.Value * 90;
            numericUpDown1.Value = trackBar2.Value * 90;
            Changed();
        }

        private void numericUpDown1_ValueChanged(object sender, EventArgs e)
        {
            trackBar1.Value = (int)Math.Round(numericUpDown1.Value);
            trackBar2.Value = (int)Math.Round(numericUpDown1.Value / 90);
            Changed();
        }


        protected override void FinalApply()
        {
            AForge.Imaging.Filters.RotateBicubic rotator = new AForge.Imaging.Filters.RotateBicubic((double)numericUpDown1.Value);
            rotator.FillColor = Color.White;
            Bitmap = rotator.Apply(Bitmap);
            InvalidateImage();            
        }
    }
}
